﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using QMERP.Domain.Entities;

namespace QMERP.Infrastructure.EFCore.Mappings
{
    public class SupplierMapping : IEntityTypeConfiguration<Supplier>
    {
        public void Configure(EntityTypeBuilder<Supplier> builder)
        {
            builder.HasQueryFilter(x => x.IsEnable);
            builder.Property(x => x.Code).HasMaxLength(10);
            builder.Property(x => x.Name).HasMaxLength(50);
            builder.Property(x => x.ShortName).HasMaxLength(20);
            builder.Property(x => x.AreaCode).HasMaxLength(20);
            builder.Property(x => x.TradeCode).HasMaxLength(20);
            builder.Property(x => x.Address).HasMaxLength(100);
            builder.Property(x => x.PostCode).IsRequired(false).HasMaxLength(20);
            builder.Property(x => x.Taxpayer).IsRequired(false).HasMaxLength(20);
            builder.Property(x => x.Bank).IsRequired(false).HasMaxLength(30);
            builder.Property(x => x.BankAccount).IsRequired(false).HasMaxLength(50);
            builder.Property(x => x.Fax).IsRequired(false).HasMaxLength(20);
            builder.Property(x => x.Email).IsRequired(false).HasMaxLength(30);
            builder.Property(x => x.ContactPerson).IsRequired(false).HasMaxLength(30);
            builder.Property(x => x.ContactType).IsRequired(false).HasMaxLength(30);
            builder.Property(x => x.CreditGrade).IsRequired(false).HasMaxLength(50);
            builder.Property(x => x.Priority).IsRequired(false);
            builder.Property(x => x.Sort).IsRequired(false);

            builder.HasIndex(x => x.Id);
            builder.HasIndex(x => x.Code);
            builder.HasIndex(x => x.Name);
            builder.HasIndex(x => x.CreatedOn).IsDescending();
        }
    }
}
